<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%
    // 创建日程
    String id = input.getDesc("id", "-1");
    Integer uid = token.getUid();
    List<Arrangement> list = QBuilder.db("basedb").select().from("Arrangement").where(new Where("hospital=", hospital).and("status=", STATUS_ENABLE).and("uid=", uid).and("id=", id)).query().getResultObj();
    if (isEmpty(list)) {
        msg = new Message(30041, "日程已不存在");
        Tools.encryptPrint(out, msg);
        return;
    }
    Arrangement ag = list.get(0);
    String team = ag.getTeam();
    List<Arrangement> ags = QBuilder.db("basedb").select().from("Arrangement").where(new Where("hospital=", hospital).and("status=", STATUS_ENABLE).and("team=", team)).query().getResultObj();
    if (isEmpty(ags)) {
        msg = new Message(30041, "暂无日程");
        msg.put("data", new ArrayList());
        Tools.encryptPrint(out, msg);
        return;
    }
    String imgStr = input.getDesc("imgs", "");
    String _imgs = ag.getImgs();
    //List imgs = GsonUtil.fromJson(_imgs, new TypeToken<List>(){});
    List imgs = new ArrayList();
    if (!isEmpty(imgStr)) {
        String[] strs = imgStr.split("\\|");
        for (int i = 0; i < strs.length; i++) {
            imgs.add(strs[i]);
        }
    }
    for (int i = 0; i < ags.size(); i++) {
        ag = ags.get(i);
        ag.setImgs(JSONUtil.toJson(imgs));
        Integer partner = ag.getPartner();
        String title = input.getDesc("title", "");
        if (!isEmpty(title)) {
            ag.setTitle(title);
        }
        String descr = input.getDesc("descr", "");
        if (!isEmpty(descr)) {
            ag.setDescr(descr);
        }
        String type = input.getDesc("type", "");
        if (!isEmpty(type)) {
            ag.setType(type);
        }
        String start = input.getDesc("start", "");
        if (!isEmpty(start)) {
            ag.setStart(start);
        }
        Long notify = input.getLong("notify", -1L);
        if (notify != -1) {
            ag.setNotify(notify);
        }
        if (notify > 0) {
            start = isEmpty(start) ? ag.getStart() : start;
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    		Date d = sdf.parse(start);
    		ag.setPushTime(d.getTime() - notify);
        }
    }
    DBTools.db("basedb").modItem(ags);
    Tools.encryptPrint(out, msg);
%>
